package com.chengjie.user.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.chengjie.common.annotation.Log;
import com.chengjie.common.core.controller.BaseController;
import com.chengjie.common.core.domain.AjaxResult;
import com.chengjie.common.enums.BusinessType;
import com.chengjie.user.domain.EpidemicPrevention;
import com.chengjie.user.service.IEpidemicPreventionService;
import com.chengjie.common.utils.poi.ExcelUtil;
import com.chengjie.common.core.page.TableDataInfo;

/**
 * 防疫记录Controller
 * 
 * @author ycj
 * @date 2022-05-02
 */
@RestController
@RequestMapping("/user/epidemicPrevention")
public class EpidemicPreventionController extends BaseController
{
    @Autowired
    private IEpidemicPreventionService epidemicPreventionService;

    /**
     * 查询防疫记录列表
     */
    @PreAuthorize("@ss.hasPermi('user:epidemicPrevention:list')")
    @GetMapping("/list")
    public TableDataInfo list(EpidemicPrevention epidemicPrevention)
    {
        startPage();
        epidemicPrevention.setCreateBy(getLoginUser().getUsername());
        List<EpidemicPrevention> list = epidemicPreventionService.selectEpidemicPreventionList(epidemicPrevention);
        return getDataTable(list);
    }

    /**
     * 导出防疫记录列表
     */
    @PreAuthorize("@ss.hasPermi('user:epidemicPrevention:export')")
    @Log(title = "防疫记录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, EpidemicPrevention epidemicPrevention)
    {
        List<EpidemicPrevention> list = epidemicPreventionService.selectEpidemicPreventionList(epidemicPrevention);
        ExcelUtil<EpidemicPrevention> util = new ExcelUtil<EpidemicPrevention>(EpidemicPrevention.class);
        util.exportExcel(response, list, "防疫记录数据");
    }

    /**
     * 获取防疫记录详细信息
     */
    @PreAuthorize("@ss.hasPermi('user:epidemicPrevention:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(epidemicPreventionService.selectEpidemicPreventionById(id));
    }

    /**
     * 新增防疫记录
     */
    @PreAuthorize("@ss.hasPermi('user:epidemicPrevention:add')")
    @Log(title = "防疫记录", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody EpidemicPrevention epidemicPrevention)
    {
        return toAjax(epidemicPreventionService.insertEpidemicPrevention(epidemicPrevention));
    }

    /**
     * 修改防疫记录
     */
    @PreAuthorize("@ss.hasPermi('user:epidemicPrevention:edit')")
    @Log(title = "防疫记录", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody EpidemicPrevention epidemicPrevention)
    {
        return toAjax(epidemicPreventionService.updateEpidemicPrevention(epidemicPrevention));
    }

    /**
     * 删除防疫记录
     */
    @PreAuthorize("@ss.hasPermi('user:epidemicPrevention:remove')")
    @Log(title = "防疫记录", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(epidemicPreventionService.deleteEpidemicPreventionByIds(ids));
    }
}
